var list=[]
var list1=[]
import Mock from 'mockjs'
    list1.push({
        num1:Mock.mock('@integer(100, 2000)'),
        num2:Mock.mock('@integer(100, 2000)'),
        num3:Mock.mock('@integer(100, 2000)'),
        num4:Mock.mock('@integer(100, 2000)'),
        num5:Mock.mock('@integer(100, 2000)'),
        num6:Mock.mock('@integer(100, 2000)'),
    })
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
for (var i=0;i<100;i++){
    var unit = Mock.mock({
        'regexp': /^交警[一二三四五]大队$/
      })
    list.push({
        id:i+1,
        unit:unit.regexp,
        workDate:Mock.mock('@date()'),
        date:Mock.mock('@datetime()'),
        road:Mock.mock('@cword(3, 5)'),
        condition:Mock.mock('@natural(0, 2)'),
    })
}
function param2Obj(url){
    const search=url.split('?')[1]
    if(!search){
        return{}
    }
    return JSON.parse('{"'+decodeURIComponent(search)
    .replace(/"/g, '\\"')
    .replace(/&/g, '","')
    .replace(/=/g, '":"') + '"}')
    }  
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

export default {
    getLjData:config=>{
        var {keyWord,page,pageSize}= param2Obj(config.url)
        var res = list.filter(item=>item.unit.indexOf(keyWord)!=-1)
        //(page-1)*pageSize <=index && < page * pageSize
        //page:1,pageSize:20
        var listLimit=res.filter((item,index)=>{
            return (page-1)*pageSize <= index &&  index < page* pageSize
        })
        return{
            code:200,
            msg:'请求成功',
            data:listLimit,
            total:list.length
        }
    },
    deleteLjData:config=>{
        // console.log(1,config.body);
        // console.log(2,JSON.parse(config.body));
        // console.log(3,JSON.parse(JSON.stringify(config.body)));
        var {id}=JSON.parse(config.body)
        var res = list.filter(item=>item.id!=id)
        list = res
        return{
            code:200,
            msg:'删除成功',
            data:null
        }
    },
    //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.
    getNumData:()=>{
        return{
            code:200,
            msg:'ok',
            data:list1
        }
    }
} 

